package cn.eveo.refreshandloadmore.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.eveo.refreshandloadmore.R;

/**
 * Created by Administrator on 2016/9/12.
 */
public class AbsListAdapter extends BaseAdapter {
    private List<String> datas;
    private Context mContext;
    private LayoutInflater layoutInflater;

    public AbsListAdapter(Context context, List<String> datas) {
        this.mContext = context;
        this.datas = datas;
        this.layoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            viewHolder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.item_adapter, null);
            viewHolder.textView = (TextView) convertView.findViewById(R.id.item_adapter_title);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        viewHolder.textView.setText(datas.get(position));

        return convertView;
    }

    static class ViewHolder {
        public TextView textView;
    }
}
